package com.example.microinvestcommon.entity;

import com.example.microinvestcommon.util.BigDecimalUtil;
import com.example.microinvestcommon.util.SnowflakeIdGeneratorUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserOrder {
    private Long orderId;
    private Long userId;
    private String stockSymbol;
    private BigDecimal orderAmount;     // 单股价格
    private BigDecimal orderAllAmount;  // 订单总金额
    private Integer stockQuantity;      // 购买数量
    private BuySell buySell;            // 交易类型（买/卖）
    private Status status;

    public enum BuySell {
        BUY,SELL,DONE,CANCEL;
    }

    public enum Status{
        DONE,CANCEL,ING
    }

    // 主要构造方法
    public UserOrder(Long userId, String stockSymbol, double orderAmount, Integer stockQuantity, BuySell buySell,Status status,SnowflakeIdGeneratorUtil snowflakeIdGenerator) {
        this.orderId= snowflakeIdGenerator.nextId();
        this.userId = userId;
        this.stockSymbol = stockSymbol;
        this.orderAmount = BigDecimal.valueOf(orderAmount);
        this.stockQuantity = stockQuantity;
        this.buySell = buySell;
        this.status=status;
        // 计算总价
        this.orderAllAmount = BigDecimal.valueOf(BigDecimalUtil.multiply(orderAmount, stockQuantity));
    }
}
